/**
 * @description:
 * @file: user.ts
 * @author: Evan
 * @date: 2025.04.08 09:23:40
 * @week: 周二
 * @version: V
 * */

import Mock from 'mockjs'
import { builder, decryptAES } from '../util'

let _USER_NAME_ = ''

export default [
  {
    url: '/user/login',
    method: 'post',
    response: (e: AnyObject) => {
      const { username, password, code } = e.body
      const pwd = decryptAES(password)
      const date = new Date()
      const year = date.getFullYear()
      const month = date.getMonth() + 1
      const day = date.getDate()
      if (
        (username == 'test' && pwd == '123456') ||
        (year == username && Number(pwd) == month && day == code)
      ) {
        _USER_NAME_ = username
        return builder({
          token_type: 'bearer',
          access_token: Mock.mock('@guid')
        })
      } else {
        return builder(void 0, '登录失败，请检查登录信息！', 500)
      }
    }
  },
  {
    url: '/user/logout',
    method: 'get',
    response: () => {
      return builder({}, '退出登录')
    }
  },
  {
    url: '/user/getUserInfo',
    method: 'get',
    response: () => {
      return builder({
        id: Mock.mock('@id'),
        username: _USER_NAME_,
        realName: Mock.mock('@cname'),
        avatar: Mock.Random.image('50x50', Mock.mock('@hex'), 'E')
      })
    }
  },
  {
    url: '/user/auth',
    method: 'get',
    response: () => {
      return builder([
        { name: '模块一', order: 10, code: 'monitor' },
        { name: '模块二', order: 20, code: 'device' },
        { name: '模块三', order: 30, code: 'ems' },
        { name: '模块四', order: 40, code: 'cm' },
        { name: '模块五', order: 50, code: 'ops' },
        { name: '模块六', order: 60, code: 'alarm' },
        { name: '模块七', order: 70, code: 'base' }
      ])
    }
  },
  {
    url: '/user/projects',
    method: 'get',
    response: () => {
      return builder(
        Mock.mock({
          'list|3-10': [
            {
              'id|+1': 1,
              name: '项目@id',
              projectCode: '@guid'
            }
          ]
        }).list
      )
    }
  },
  {
    url: '/user/project/get',
    method: 'get',
    response: () => {
      return builder(
        Mock.mock({
          id: Mock.mock('@id'),
          name: Mock.mock('@ctitle(5, 10)')
          // logo: Mock.Random.image('130x40', Mock.mock('@hex'), 'LOGO'),
          // logoSmall: Mock.Random.image('50x50', Mock.mock('@hex'), 'E')
        })
      )
    }
  },
  {
    url: '/test/delete',
    method: 'delete',
    response: () => {
      return ''
    }
  },
  {
    url: '/test/post',
    method: 'post',
    response: () => {
      return ''
    }
  }
]
